package com.lane.sidecn.user;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.junit.Test;

import com.lane.sidecn.user.model.Customer;

/**
 * @author 张先宙 E-mail: zhangxianzhou_std@163.com
 * @version 1.0 创建时间：Jul 1, 2009 8:10:18 PM
 * 
 */

public class CustomerTestCase extends TestCase {

	private Session session;

	protected void setUp() throws Exception {
		try {

			Configuration config = new Configuration().configure();
			SessionFactory sessionFactory = config.buildSessionFactory();
			session = sessionFactory.openSession();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	protected void tearDown() throws Exception {
		session.close();
	}

	@Test
	public void testRegister() {
		try {
			Customer customer = new Customer();

			customer.setPassword("Andy");

			session.save(customer);
			session.flush();
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail(e.getLocalizedMessage());
		}
	}

	@Test
	public void testLogin() {
		try {
			Customer customer = new Customer();

			customer.setEmail("zhangxianzhou_std@163.com");

			customer.setPassword("Andy");

			session.save(customer);
			session.flush();
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail(e.getLocalizedMessage());
		}
	}

	@Test
	public void testModifyPsw() {
		try {
			Customer customer = new Customer();

			customer.setEmail("zhangxianzhou_std@163.com");

			customer.setPassword("Andy");

			session.save(customer);
			session.flush();
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail(e.getLocalizedMessage());
		}
	}

	@Test
	public void testValidateExist() {
		try {
			Customer customer = new Customer();

			customer.setEmail("zhangxianzhou_std@163.com");

			customer.setPassword("Andy");

			session.save(customer);
			session.flush();
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail(e.getLocalizedMessage());
		}
	}

}
